from utils.time import get_dates


def generate_sql(sql, fields, months_back):
    """优化后的SQL生成器"""
    start_date, end_date = get_dates(months_back)
    return f"SELECT * FROM {sql} WHERE {fields} BETWEEN '{start_date}' AND '{end_date}'"